package com.xxx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xxx.controller.utils.R;
import com.xxx.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Random;

@RestController
@RequestMapping("/collection")
public class CollectionController extends BaseController{
    @Autowired
    private CollectionService collectionService;

    //分页获取收藏功能
    @RequestMapping("/getPageCollection")
    public R getPageCollection(Integer currentPage, HttpSession session){
        IPage iPage = collectionService.getPageCollection(currentPage, getUidFromSession(session));
        return new R(OK,iPage);
    }

    //添加收藏的功能
    @RequestMapping("/addCollection")
    public R addCollection(Integer pid,HttpSession session){
        collectionService.addCollection(pid,getUidFromSession(session),getUsernameFromSession(session));
        return new R(OK);
    }

    //移除收藏的功能
    @RequestMapping("/removeCollection")
    public R removeCollection(Integer id){
        collectionService.removeCollection(id);
        return new R(OK);
    }
}
